home *** CD-ROM | disk | FTP | other *** search
- 10 ! ******************************************************************
- 20 !
- 30 ! Example: Bitmap Viewer
- 40 !
- 50 ! This program demonstrates the use of the BITMAP widget. It
- 60 ! allows you to bring in and display bitmaps, as well as select
- 70 ! portions of them and save them in a file.
- 80 !
- 90 ! It also demonstrates the SCROLLABLE attribute for the PANEL ...
- 100 ! in particular the various operations needed to make SCROLL WIDTH
- 110 ! and SCROLL HEIGHT as correct as possible..
- 120 !
- 130 ! ******************************************************************
- 140 !
- 150 ! A few variables:
- 160 !
- 170 ! S$: General-purpose string.
- 180 ! N: General-purpose variable.
- 190 ! Btn: Returns button value from dialogs.
- 200 ! Sc: Scroll factor.
- 210 ! Bitfile$: Name of bitmap file to be read.
- 220 ! Dirname$: Directory name returned from FILE dialog.
- 230 ! B1$(*): Stores MENU BUTTONS.
- 240 ! A1$,A2$: Stores dialog attributes.
- 250 !
- 260 DIM S$[256]
- 270 INTEGER N,Btn,Sc
- 280 DIM Bitfile$[100],Dirname$[100],Btns$(1:3)[50],A1$[50],A2$[50]
- 290 !
- 300 DATA "BMP File","XWD File","Cancel","DIALOG BUTTONS","SELECTION",20
- 310 READ Btns$(*),A1$,A2$,Sc
- 320 !
- 330 ! Widget dimensions.
- 340 !
- 350 INTEGER Pw,Ph,Px,Py,Iw,Ih,Ww,Wh,Wx,Wy
- 360 !
- 370 ! Variables for display scaling.
- 380 !
- 390 INTEGER Cursor,D(1:4),Dw,Dh
- 400 !
- 410 ! Get display size.
- 420 !
- 430 GESCAPE CRT,3;D(*)
- 440 Dw=D(3)-D(1)
- 450 Dh=D(4)-D(2)
- 460 !
- 470 CLEAR SCREEN
- 480 KEY LABELS OFF
- 490 RUNLIGHT OFF
- 500 STATUS CRT,10;Cursor
- 510 CONTROL CRT,10;0
- 520 !
- 530 Pw=Dw*.7 ! PANEL width.
- 540 Ph=Dh*.7 ! PANEL height.
- 550 Px=(Dw-Pw)/2 ! Center PANEL.
- 560 Py=(Dh-Ph)/2
- 570 !
- 580 ! Create PANEL for BITMAP widget. Note how the SCROLL WIDTH
- 590 ! and HEIGHT are set to a small value so that scroll bars will not
- 600 ! appear initially. The actual heights are set later to fit the bitmap
- 610 ! that has been loaded.
- 620 !
- 630 ASSIGN @Main TO WIDGET "PANEL";SET ("VISIBLE":0)
- 640 CONTROL @Main;SET ("X":Px,"Y":Py,"WIDTH":Pw,"HEIGHT":Ph)
- 650 CONTROL @Main;SET ("TITLE":"Example: Bitmap Viewer")
- 660 CONTROL @Main;SET ("SIZE CONTROL":"SCROLLABLE","MINIMIZABLE":1)
- 670 CONTROL @Main;SET ("SCROLL WIDTH":1,"SCROLL WIDTH UNITS":Sc)
- 680 CONTROL @Main;SET ("SCROLL HEIGHT":1,"SCROLL HEIGHT UNITS":Sc)
- 690 !
- 700 ! Build menu.
- 710 !
- 720 ASSIGN @Menu TO WIDGET "PULLDOWN MENU";PARENT @Main
- 730 CONTROL @Menu;SET ("LABEL":"Menu")
- 740 ASSIGN @Getfile TO WIDGET "MENU BUTTON";PARENT @Menu
- 750 CONTROL @Getfile;SET ("LABEL":"Get Bitmap File")
- 760 ASSIGN @Savefile TO WIDGET "MENU BUTTON";PARENT @Menu
- 770 CONTROL @Savefile;SET ("LABEL":"Cut Bitmap To File")
- 780 ASSIGN @Cd TO WIDGET "MENU BUTTON";PARENT @Menu
- 790 CONTROL @Cd;SET ("LABEL":"Change Directory")
- 800 ASSIGN @S TO WIDGET "MENU SEPARATOR";PARENT @Menu
- 810 ASSIGN @Quit TO WIDGET "MENU BUTTON";PARENT @Menu
- 820 CONTROL @Quit;SET ("LABEL":"Quit")
- 830 !
- 840 ! Create and size BITMAP widget. (Setting RETAIN RASTER makes the
- 850 ! widget redraw quickly when overwritten by a dialog.)
- 860 !
- 870 ASSIGN @Bitmap TO WIDGET "BITMAP";PARENT @Main
- 880 CONTROL @Bitmap;SET ("RETAIN RASTER":1,"AUTO SIZE":1)
- 890 STATUS @Main;RETURN ("INSIDE WIDTH":Iw,"INSIDE HEIGHT":Ih)
- 900 Wx=Iw*.01
- 910 Wy=Ih*.01
- 920 Wh=Ih*.98
- 930 Ww=Iw*.98
- 940 CONTROL @Bitmap;SET ("X":Wx,"Y":Wy,"WIDTH":Ww,"HEIGHT":Wh)
- 950 !
- 960 ! Set events.
- 970 !
- 980 ON EVENT @Getfile,"ACTIVATED" GOSUB Getbitfile
- 990 ON EVENT @Savefile,"ACTIVATED" GOSUB Savebits
- 1000 ON EVENT @Cd,"ACTIVATED" GOSUB Chdir
- 1010 ON EVENT @Quit,"ACTIVATED" GOTO Finis
- 1020 !
- 1030 CONTROL @Main;SET ("VISIBLE":1)
- 1040 !
- 1050 ! Loop and wait for input.
- 1060 !
- 1070 LOOP
- 1080 END LOOP
- 1090 STOP
- 1100 !
- 1110 ! *********************** End of Main Program **********************
- 1120 !
- 1130 ! This routine gets a bitmap file and displays it. Note how it gets
- 1140 ! the bitmap size and sets up PANEL scrolling accordingly. Note also
- 1150 ! how it turns the BITMAP widget invisible so the display will
- 1160 ! "thrash" as little as possible.
- 1170 !
- 1180 Getbitfile: !
- 1190 S$="Please enter the name of a bitmap (.XWD or .BMP) file:"
- 1200 DIALOG "FILE",S$,Btn;RETURN ("SELECTION":Bitfile$)
- 1210 !
- 1220 IF Btn=0 THEN
- 1230 CLEAR ERROR
- 1240 ON ERROR GOSUB Errtrap
- 1250 CONTROL @Bitmap;SET ("VISIBLE":0,"BITMAP FILE":Bitfile$)
- 1260 OFF ERROR
- 1270 IF ERRN<>0 THEN
- 1280 DIALOG "ERROR","Can't open file / invalid bitmap file."
- 1290 CONTROL @Bitmap;SET ("BITMAP FILE":"","VISIBLE":1)
- 1300 ELSE
- 1310 CONTROL @Bitmap;SET ("VISIBLE":0)
- 1320 STATUS @Bitmap;RETURN ("BITMAP HEIGHT":Wh,"BITMAP WIDTH":Ww)
- 1330 CONTROL @Main;SET ("SCROLL HEIGHT":2+INT(Wh/Sc))
- 1340 CONTROL @Main;SET ("SCROLL WIDTH":2+INT(Ww/Sc))
- 1350 CONTROL @Bitmap;SET ("VISIBLE":1)
- 1360 DIALOG "INFORMATION","File read completed!"
- 1370 END IF
- 1380 END IF
- 1390 RETURN
- 1400 !
- 1410 ! This routine allows you to cut a section of a bitmap and
- 1420 ! save it in a file. Note how string variables are used in
- 1430 ! the FILE dialog to specify the DIALOG BUTTONS attribute and
- 1440 ! the SELECTION attribute in order to keep the length of the
- 1450 ! statement compact.
- 1460 !
- 1470 Savebits: !
- 1480 S$="Enter file name, then click-and-drag image to save:"
- 1490 DIALOG "FILE",S$,Btn;SET (A1$:Btns$(*)),RETURN (A2$:Bitfile$)
- 1500 !
- 1510 SELECT Btn
- 1520 CASE 0
- 1530 S$="BMP" ! Dump format is MS-Windows .BMP file.
- 1540 CASE 1
- 1550 S$="XWD" ! Dump format is X11 XWD format.
- 1560 CASE 2
- 1570 RETURN
- 1580 END SELECT
- 1590 !
- 1600 CLEAR ERROR
- 1610 ON ERROR GOSUB Errtrap
- 1620 CONTROL @Bitmap;SET ("DUMP FORMAT":S$,"DUMP AREA":Bitfile$)
- 1630 OFF ERROR
- 1640 IF ERRN<>0 THEN
- 1650 DIALOG "ERROR","Can't open file."
- 1660 ELSE
- 1670 DIALOG "INFORMATION","Bitmap saved to "&S$&" file."
- 1680 END IF
- 1690 !
- 1700 RETURN
- 1710 !
- 1720 ! This routine changes directories.
- 1730 !
- 1740 Chdir: !
- 1750 S$="Please enter the name of a directory:"
- 1760 DIALOG "FILE",S$,Btn;RETURN ("DIRECTORY":Dirname$)
- 1770 !
- 1780 Err=0
- 1790 CLEAR ERROR
- 1800 ON ERROR GOSUB Errtrap
- 1810 MASS STORAGE IS Dirname$
- 1820 OFF ERROR
- 1830 IF ERRN<>0 THEN
- 1840 DIALOG "ERROR","Can't change directory!"
- 1850 END IF
- 1860 RETURN
- 1870 !
- 1880 ! Dummy routine for trapping errors.
- 1890 !
- 1900 Errtrap: ERROR RETURN
- 1910 !
- 1920 ! ************** Go Here When Done ***********************
- 1930 !
- 1940 Finis: !
- 1950 ASSIGN @Main TO *
- 1960 CLEAR SCREEN
- 1970 KEY LABELS ON
- 1980 RUNLIGHT ON
- 1990 CONTROL CRT,10;Cursor
- 2000 END
-